import path from 'path';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';

// import Components from 'unplugin-vue-components/vite'
// import ElementPlus from 'unplugin-element-plus/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig((env) => ({
    esbuild: {
      jsxFactory: 'h',
      jsxFragment: 'Fragement',
    },
    resolve: {
      alias: {
        '~': path.resolve(__dirname, 'node_modules'),
        '@core': path.resolve(__dirname, 'src/core'),
        '@pages': path.resolve(__dirname, 'src/pages'),
        '@assets': path.resolve(__dirname, 'src/assets'),
        '@components': path.resolve(__dirname, 'src/pages/components'),
      },
    },
      //跨域
    server: {
      host: '0.0.0.0',
      proxy: {
        '/api/': {
          target: 'http://127.0.0.1:8888',
        },
      },
    },
    plugins: [
      vue(),
      vueJsx()
      // Components({
      //   resolvers: [ElementPlusResolver()],
      // }),
      // ElementPlus({
      //   useSource: true,
      // })
    ],
    // css: {
    //   preprocessorOptions: {
    //     scss: {
    //       additionalData: `@use "@assets/css/element-variables.scss" as *;`,
    //     },
    //   },
    // },
    build: {
      rollupOptions: {
        output: {
          manualChunks: {
            lodash: ["lodash"],
            "element-plus": ["element-plus"],
            'axios': ['axios']
          },
        },
      },
      chunkSizeWarningLimit: 1024,
      emptyOutDir: true,
      sourcemap: env.mode === 'test' ? true : false,
    }
  })
);
